home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / cvs-1_3.lha / cvs-1.3 / src / vers_ts.c < prev    next >
C/C++ Source or Header  |  1992-03-31  |  5KB  |  225 lines

  1. /*
  2.  * Copyright (c) 1992, Brian Berliner and Jeff Polk
  3.  * Copyright (c) 1989-1992, Brian Berliner
  4.  * 
  5.  * You may distribute under the terms of the GNU General Public License as
  6.  * specified in the README file that comes with the CVS 1.3 kit.
  7.  */
  8.  
  9. #include "cvs.h"
  10.  
  11. #ifndef lint
  12. static char rcsid[] = "@(#)vers_ts.c 1.36 92/03/31";
  13. #endif
  14.  
  15. extern char *ctime ();            /* XXX - should use gmtime/asctime */
  16.  
  17. /*
  18.  * Fill in and return a Vers_TS structure "user" is the name of the local
  19.  * file; entries is the entries file - preparsed for our pleasure. xfiles is
  20.  * all source code control files, preparsed for our pleasure
  21.  */
  22. Vers_TS *
  23. Version_TS (repository, options, tag, date, user, force_tag_match,
  24.         set_time, entries, xfiles)
  25.     char *repository;
  26.     char *options;
  27.     char *tag;
  28.     char *date;
  29.     char *user;
  30.     int force_tag_match;
  31.     int set_time;
  32.     List *entries;
  33.     List *xfiles;
  34. {
  35.     Node *p;
  36.     RCSNode *rcsdata;
  37.     Vers_TS *vers_ts;
  38.     struct stickydirtag *sdtp;
  39.  
  40.     /* get a new Vers_TS struct */
  41.     vers_ts = (Vers_TS *) xmalloc (sizeof (Vers_TS));
  42.     bzero ((char *) vers_ts, sizeof (*vers_ts));
  43.  
  44.     /*
  45.      * look up the entries file entry and fill in the version and timestamp
  46.      * if entries is NULL, there is no entries file so don't bother trying to
  47.      * look it up (used by checkout -P)
  48.      */
  49.     if (entries == NULL)
  50.     {
  51.     sdtp = NULL;
  52.     p = NULL;
  53.     }
  54.     else
  55.     {
  56.     p = findnode (entries, user);
  57.     sdtp = (struct stickydirtag *) entries->list->data; /* list-private */
  58.     }
  59.  
  60.     if (p != NULL)
  61.     {
  62.     Entnode *entdata = (Entnode *) p->data;
  63.  
  64.     vers_ts->vn_user = xstrdup (entdata->version);
  65.     vers_ts->ts_rcs = xstrdup (entdata->timestamp);
  66.     if (!tag)
  67.     {
  68.         if (!(sdtp && sdtp->aflag))
  69.         vers_ts->tag = xstrdup (entdata->tag);
  70.     }
  71.     if (!date)
  72.     {
  73.         if (!(sdtp && sdtp->aflag))
  74.         vers_ts->date = xstrdup (entdata->date);
  75.     }
  76.     if (!options || (options && *options == '\0'))
  77.     {
  78.         if (!(sdtp && sdtp->aflag))
  79.         vers_ts->options = xstrdup (entdata->options);
  80.     }
  81.     vers_ts->entdata = entdata;
  82.     }
  83.  
  84.     /*
  85.      * -k options specified on the command line override (and overwrite)
  86.      * options stored in the entries file
  87.      */
  88.     if (options)
  89.     vers_ts->options = xstrdup (options);
  90.     else if (sdtp && sdtp->aflag == 0)
  91.     {
  92.     if (!vers_ts->options)
  93.         vers_ts->options = xstrdup (sdtp->options);
  94.     }
  95.     if (!vers_ts->options)
  96.     vers_ts->options = xstrdup ("");
  97.  
  98.     /*
  99.      * if tags were specified on the command line, they override what is in
  100.      * the Entries file
  101.      */
  102.     if (tag || date)
  103.     {
  104.     vers_ts->tag = xstrdup (tag);
  105.     vers_ts->date = xstrdup (date);
  106.     }
  107.     else if (!vers_ts->entdata && (sdtp && sdtp->aflag == 0))
  108.     {
  109.     if (!vers_ts->tag)
  110.         vers_ts->tag = xstrdup (sdtp->tag);
  111.     if (!vers_ts->date)
  112.         vers_ts->date = xstrdup (sdtp->date);
  113.     }
  114.  
  115.     /* Now look up the info on the source controlled file */
  116.     if (xfiles != (List *) NULL)
  117.     {
  118.     p = findnode (xfiles, user);
  119.     if (p != NULL)
  120.     {
  121.         rcsdata = (RCSNode *) p->data;
  122.         rcsdata->refcount++;
  123.     }
  124.     else
  125.         rcsdata = NULL;
  126.     }
  127.     else
  128.     rcsdata = RCS_parse (user, repository);
  129.  
  130.     if (rcsdata != NULL)
  131.     {
  132.     /* squirrel away the rcsdata pointer for others */
  133.     vers_ts->srcfile = rcsdata;
  134.  
  135.     /* get RCS version number into vn_rcs (if appropriate) */
  136.     if (((vers_ts->tag || vers_ts->date) && force_tag_match) ||
  137.         ((rcsdata->flags & VALID) && (rcsdata->flags & INATTIC) == 0))
  138.     {
  139.         if (vers_ts->tag && strcmp (vers_ts->tag, TAG_BASE) == 0)
  140.         vers_ts->vn_rcs = xstrdup (vers_ts->vn_user);
  141.         else
  142.         vers_ts->vn_rcs = RCS_getversion (rcsdata, vers_ts->tag,
  143.                         vers_ts->date, force_tag_match);
  144.     }
  145.  
  146.     /*
  147.      * If the source control file exists and has the requested revision,
  148.      * get the Date the revision was checked in.  If "user" exists, set
  149.      * its mtime.
  150.      */
  151.     if (set_time)
  152.     {
  153.         struct utimbuf t;
  154.  
  155.         if (vers_ts->vn_rcs &&
  156.         (t.actime = t.modtime = RCS_getrevtime (rcsdata, vers_ts->vn_rcs,
  157.                             (char *) 0, 0)) != -1)
  158.         (void) utime (user, &t);
  159.     }
  160.     }
  161.  
  162.     /* get user file time-stamp in ts_user */
  163.     if (entries != (List *) NULL)
  164.     vers_ts->ts_user = time_stamp (user);
  165.  
  166.     return (vers_ts);
  167. }
  168.  
  169. /*
  170.  * Gets the time-stamp for the file "file" and returns it in space it
  171.  * allocates
  172.  */
  173. char *
  174. time_stamp (file)
  175.     char *file;
  176. {
  177.     struct stat sb;
  178.     char *cp;
  179.     char *ts;
  180.  
  181.     if (stat (file, &sb) < 0)
  182.     {
  183.     ts = NULL;
  184.     }
  185.     else
  186.     {
  187.     ts = xmalloc (51);        /* 51 = 2 ctime strings + NULL */
  188.     cp = ctime (&sb.st_ctime);    /* copy in the create time */
  189.     cp[24] = ' ';
  190.     (void) strcpy (ts, cp);
  191.     cp = ctime (&sb.st_mtime);    /* copy in the modify time */
  192.     cp[24] = '\0';
  193.     (void) strcat (ts, cp);
  194.     }
  195.  
  196.     return (ts);
  197. }
  198.  
  199. /*
  200.  * free up a Vers_TS struct
  201.  */
  202. void
  203. freevers_ts (versp)
  204.     Vers_TS **versp;
  205. {
  206.     if ((*versp)->srcfile)
  207.     freercsnode (&((*versp)->srcfile));
  208.     if ((*versp)->vn_user)
  209.     free ((*versp)->vn_user);
  210.     if ((*versp)->vn_rcs)
  211.     free ((*versp)->vn_rcs);
  212.     if ((*versp)->ts_user)
  213.     free ((*versp)->ts_user);
  214.     if ((*versp)->ts_rcs)
  215.     free ((*versp)->ts_rcs);
  216.     if ((*versp)->options)
  217.     free ((*versp)->options);
  218.     if ((*versp)->tag)
  219.     free ((*versp)->tag);
  220.     if ((*versp)->date)
  221.     free ((*versp)->date);
  222.     free ((char *) *versp);
  223.     *versp = (Vers_TS *) NULL;
  224. }
  225.